# vim:ts=8 sw=4 noet:
#

PDFLATEX = pdflatex
NOTANGLE = notangle
NOWEAVE  = noweave

# -- high-level targets
.PHONY:	    all doc clean pdf test

all:	    badges doc test

doc:	    badges.pdf

clean:
	    rm -f *.log *.aux *.inc *.tex *.out *.toc
	    
clobber:    clean
	    rm -f badges.ps .ps badges.pdf
	    rm -f sample.pdf sample.ps
	    rm -f test.*
	    rm -f badges

dist:	    badges badges.pdf 
	    rsync badges badges.pdf vistabella.de:/var/www/badges

# -- rules

sample.ps:  badges.nw
	    $(NOTANGLE) -Rsample.ps $< > $@

badges:	    badges.nw
	    $(NOTANGLE) -Rbadges.rb $< > $@
	    chmod +x $@

%.pdf:	    %.ps
	    gs -sDEVICE=pdfwrite -dBATCH -sOutputFile=$@ -dNOPAUSE $<

%.pdf:	    %.eps
	    gs -sDEVICE=pdfwrite -dBATCH -sOutputFile=$@ -dNOPAUSE $<

# -- documentation

RERUN =     Rerun (LaTeX|to get cross-references right)

pdf:	    $(PDF)

%.pdf:	%.tex 
	    $(PDFLATEX) $<
	    if egrep -s '$(RERUN)' $*.log ;then $(PDFLATEX) $<; fi
	    if egrep -s '$(RERUN)' $*.log ;then $(PDFLATEX) $<; fi

%.tex:      %.nw
	    $(NOWEAVE) -delay $< > $@

# -- Tests

.PHONY:	    test

test:	    test.ps test.pdf Makefile

OPTS=	    -o 0,-1,0,1 -s "Frontiers of^Electronic Voting" -d 1234 \
	    -n 07000 \
	    -b grey \
	    -i "Don't miss the vernissage on Tuesday!" \
	    -c background:seminar:name:affil:doorcode:semnr:phone:info:login \
	    -c name:affil:background:seminar:placecard:diet:dietmarks:cutmarks

test.ps:    badges Makefile testcases.txt
	    ./badges $(OPTS) < testcases.txt > $@

lindig.ps:  lindig.txt
	    cat lindig.txt | ./badges -s "Scientific Staff" -b yellow \
	    -c background:seminar:name:affil:cutmarks > lindig.ps
